package com.gitee.fastmybatis.spring.boot.autoconfigure.multi;

import java.util.Map;

public class DatasourcePropContext {

    private final String dsAlias;
    private final DataSourceProp dataSourceProp;
    private final boolean main;

    private DatasourcePropContext(String dsAlias, DataSourceProp dataSourceProp, boolean main) {
        this.dsAlias = dsAlias;
        this.dataSourceProp = dataSourceProp;
        this.main = main;
    }

    public static DatasourcePropContext of(Map.Entry<String, DataSourceProp> entry) {
        return new DatasourcePropContext(entry.getKey(), entry.getValue(), entry.getValue().getMain());
    }

    public static DatasourcePropContext ofMain(Map.Entry<String, DataSourceProp> entry) {
        return new DatasourcePropContext(entry.getKey(), entry.getValue(), true);
    }

    public static DatasourcePropContext ofNotMain(Map.Entry<String, DataSourceProp> entry) {
        return new DatasourcePropContext(entry.getKey(), entry.getValue(), false);
    }

    public String getDsAlias() {
        return dsAlias;
    }

    public boolean isMain() {
        return main;
    }

    public DataSourceProp getDataSourceProp() {
        return dataSourceProp;
    }
}
